package com.ylz.sjzx.sio.common.core.utils;

import cn.hutool.core.util.StrUtil;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Description:
 *
 * @date:2021/9/15
 * @author:wiqi
 */
public class HostUtil {
    private static String completeAddress;
    private static String hostAddress;

    /**
     * 获取完整的地址 IP加端口号
     *
     * @return
     */
    public static String getCompleteAddress() {
        if (StrUtil.isBlank(completeAddress)) {
            try {
                completeAddress = InetAddress.getLocalHost().getHostAddress() + ":" + YmlUtil.getImServiceHost();
            } catch (Exception e) {
                System.exit(500);
            }
        }

        return completeAddress;
    }

    public static String getHostAddress() {
        if (StrUtil.isBlank(hostAddress)) {
            try {
                hostAddress = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException e) {
                System.exit(500);
            }
        }

        return hostAddress;
    }

}
